package com.gao.list;

import com.gao.domain.Student;

import java.util.ArrayList;
import java.util.Scanner;

/**
 * @Author: ShanYuqing
 * @Version: v1.0
 */
public class ArrayListTest3 {
    /*
        需求：创建一个存储对象的集合，存储3个学生对象，使用程序实现在控制台遍历该集合
                学生的姓名和年龄来自键盘录入
     */
    public static void main(String[] args) {
        ArrayList<Student> list = new ArrayList<>();
        for (int i = 0; i < 3; i++) {
            System.out.println("请输入第"+(i+1)+"学生的信息：");
            addStudent(list);
        }
        for (int i = 0; i < list.size(); i++) {
             Student student = list.get(i);
            System.out.println(student.getName()+"-----"+student.getAge());
        }

    }

    private static void addStudent(ArrayList<Student> list) {
        Scanner sc = new Scanner(System.in);
        Student stu = new Student();
        System.out.println("请输入学生姓名：");
        stu.setName(sc.next());
        System.out.println("请输入学生年龄：");
        stu.setAge(sc.nextInt());
        list.add(stu);
    }
}
